/* eslint-disable */
import { useRouteStore } from "@/store/route/route";
import { getLocal } from "@/utils/store/local";
import { NavigationGuardNext, RouteLocationNormalized, Router, routerKey } from "vue-router";
import { routeName } from "../public/constRoutes";
import teacherRoute from "../teacher/route";

/**
 * 动态路由
 */
export async function createDynamicRouteGuard(
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: NavigationGuardNext,
    router: Router
) {
    const route = useRouteStore()

    const isLogin = Boolean(getLocal('token'));

    // if (!route.isAddedDynamicRoute) {
    //     if (!isLogin) {
    //         if (to.name === routeName('login')) {
    //             next()
    //         } else {
    //             next({ name: routeName('login') });
    //         }
    //         return false
    //     }

    await route.initDynamicRoute(router)

    // next()
    // }
    if (to.name === routeName('not-found-page')) {
        next({ path: to.fullPath, replace: true, query: to.query })
        return false
    }

    return true
}